//****************************************************************************
// Copyright (c) 2011-2013,WebJet Business Division,CYOU

// http://www.genesis-3d.com.cn

// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the Software), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//*****************************************************************************
Shader "PostEffect_GlowBright" {
	Parameters{
		Vector [_vsTapOffs0] = "0.0,0.0,0.0,0.0"
		Vector [_vsTapOffs1] = "0.0,0.0,0.0,0.0"
	}
	
	RenderQueue "CUSTOMDRAW"
	
	

			CODEBEGIN
			
			float4 _vsTapOffs0;
			float4 _vsTapOffs1;

			struct VS_OUTPUT
			{
				float4 Position		: POSITION0;   // vertex position 
				float2 Tex0		: TEXCOORD0;
				float2 Tex1          : TEXCOORD1;
				float2 Tex2          : TEXCOORD2;
				float2 Tex3          : TEXCOORD3;
			};

			struct PS_INPUT
			{
				float2 Tex0		: TEXCOORD0;
				float2 Tex1          : TEXCOORD1;
				float2 Tex2          : TEXCOORD2;
				float2 Tex3          : TEXCOORD3;
			};
			
			VS_OUTPUT mainVs(in float3 vPos : POSITION, in float2 vTex : TEXCOORD0)
			{
				VS_OUTPUT Output;

				Output.Position = float4(vPos.xyz, 1.0f);
				Output.Tex0.xy = vTex.xy + _vsTapOffs0.xy;
				Output.Tex1.xy = vTex.xy + _vsTapOffs0.zw;
				Output.Tex2.xy = vTex.xy + _vsTapOffs1.xy;
				Output.Tex3.xy = vTex.xy + _vsTapOffs1.zw;

				return Output;
			}

			float4 mainPs(PS_INPUT o) : COLOR0
			{
				float3 lumFactor = float3(0.298999995f, 0.587000012f, 0.114f);

				float4 sceneColor0 = tex2D(g_MainBuffer, o.Tex0.xy);
				float4 sceneColor1 = tex2D(g_MainBuffer, o.Tex1.xy);
				float4 sceneColor2 = tex2D(g_MainBuffer, o.Tex2.xy);
				float4 sceneColor3 = tex2D(g_MainBuffer, o.Tex3.xy);
				
				float4 avgColor;
				float4 sceneColor;

        avgColor.xyz = (sceneColor0.xyz + sceneColor1.xyz + sceneColor2.xyz + sceneColor3.xyz) * 0.25f;
			  sceneColor.xyz = avgColor.xyz;
			  sceneColor.w = 1.0f;

			  return sceneColor;
			}
			CODEEND
       Technique{
		Pass{
		          Compiler
			          {
				       VertexShader = mainVs
				       PixelShader = mainPs			
			
			          }

		
			RenderSTATE { 
							cullMode "Back"
							ZTest Off
							ZWrite Off
							blendMode Off
							alphatest Off
							samplerState "g_MainBuffer" [Clamp] [Linear]
				     }
		}
	}
}